package com.test;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ViewFlipper;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity {
	
	private Gallery gallery;
	private ViewFlipper flipper;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		flipper = (ViewFlipper) findViewById(R.id.flipper);
		flipper.startFlipping();
		
		gallery = (Gallery) findViewById(R.id.gallery);
		gallery.setAdapter(new ImageAdapter(this));
		registerForContextMenu(gallery);
		gallery.setOnItemClickListener(new OnItemClickListener(){

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				if(position==0){
					startActivity(new Intent(MainActivity.this, UserActivity.class));
				}else if(position==1){
					startActivity(new Intent(MainActivity.this, NewAccount.class));
				}else if(position==2){
					startActivity(new Intent(MainActivity.this, GuestActivity.class));
				}else if(position==3){
					startActivity(new Intent(MainActivity.this, AdminActivity.class));
				}
			}
			
		});
		
		
		
	}
	
	public class ImageAdapter extends BaseAdapter{
		int galleryItem;
		private Context context;
		
		private int[] ImageId = {R.drawable.user, R.drawable.sign, R.drawable.guest, R.drawable.key};
		
		public ImageAdapter(Context context){
			this.context = context;
			
			TypedArray array = obtainStyledAttributes(R.styleable.Gallery1);
			galleryItem = array.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
			array.recycle();
		}

		public int getCount() {
			// TODO Auto-generated method stub
			return ImageId.length;
		}

		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ImageView imageView = new ImageView(context);
			imageView.setImageResource(ImageId[position]);
			imageView.setScaleType(ImageView.ScaleType.FIT_XY);
			imageView.setLayoutParams(new Gallery.LayoutParams(360, 480));
			imageView.setBackgroundResource(galleryItem);
			return imageView;
		}
		
	}
}